
public class Demo18 {
    public static void main(String[] args) {
        System.out.println(SingletonLazy.getInstance());
    }
}
/*class SingletonLazy {
    private static SingletonLazy instance = null;

    public static SingletonLazy getInstance() {
        if(instance == null) {
            instance = new SingletonLazy();
        }
        return instance;
    }
    private SingletonLazy() {

    }
}*/
/*class SingletonLazy {
    private static SingletonLazy instance = null;
    private static Object block = new Object();
    public static SingletonLazy getInstance() {
        synchronized(block){
            if(instance == null) {
                instance = new SingletonLazy();
            }
            return instance;
        }
    }
    private SingletonLazy() {

    }
}*/
/*class SingletonLazy {
    private static SingletonLazy instance = null;
    private static Object block = new Object();
    public static SingletonLazy getInstance() {
        if(instance == null) {
            synchronized (block) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy() {

    }
}*/
class SingletonLazy {
    private volatile static SingletonLazy instance = null;
    private static Object block = new Object();

    public static SingletonLazy getInstance() {
        if (instance == null) {
            synchronized (block) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    private SingletonLazy() {

    }
}
